package com.glhtgyxy.biyesheji.Controller;

import com.glhtgyxy.biyesheji.Pojo.house;
import com.glhtgyxy.biyesheji.Pojo.house_time;
import com.glhtgyxy.biyesheji.Pojo.merchant;
import com.glhtgyxy.biyesheji.Pojo.order;
import com.glhtgyxy.biyesheji.Service.merchantService;
import com.glhtgyxy.biyesheji.Service.orderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

@Controller
@RequestMapping("order")
@CrossOrigin(origins = "*")
public class orderController {

    @Autowired
    orderService service;

    @ResponseBody
    @RequestMapping("findallorder")
    public ArrayList<order> findallorder(){
        System.out.println("所有订单查询中..");
        ArrayList<order> orders = service.findallorder();
        System.out.println("查询完毕，返回:"+orders);
        return orders;
    }

    @ResponseBody
    @RequestMapping("deleteorder/{id}")
    public boolean deleteorder(@PathVariable int id){
        System.out.println("删除订单中..id: "+ id);
        boolean flg =true;
        flg = service.deleteorder(id);
        System.out.println("删除完毕，返回:"+flg);
        return flg;
    }

    @ResponseBody
    @RequestMapping("finduserorder/{id}")
    public ArrayList<house_time> finduserorder(@PathVariable int id){
        System.out.println("查找用户订单..id: "+ id);
        ArrayList<house_time> housers = service.finduserorder(id);
        System.out.println("查询完毕，返回:"+housers);
        return housers;
    }

    @ResponseBody
    @RequestMapping("findmerchantorder/{id}")
    public ArrayList<house_time> findmerchantorder(@PathVariable int id){
        System.out.println("查找商户订单..id: "+ id);
        ArrayList<house_time> housers = service.findmerchantorder(id);
        System.out.println("查询完毕，返回:"+housers);
        return housers;
    }

    @ResponseBody
    @RequestMapping("deleteuserorder/{userid}/{houseid}")
    public boolean deleteuserorder(@PathVariable int userid , @PathVariable int houseid){
        System.out.println("删除用户订单..userid: "+ userid + "houseid:"+houseid);
        boolean flg = true;
        flg = service.deleteuserorder(userid,houseid);
        System.out.println("删除完毕，返回:"+flg);
        return flg;
    }




    @ResponseBody
    @RequestMapping("searchorder/{searchtext}")
    public ArrayList<order> searchtext(@PathVariable String  searchtext){
        System.out.println("订单查询中.."+searchtext);
        ArrayList<order> orders = service.search(searchtext);
        System.out.println("查询完毕，返回:"+orders);
        return orders;
    }

    @ResponseBody
    @RequestMapping("updateorder/{id}/{houseid}/{userid}")
    public boolean updateorder(@PathVariable int  id,
                               @PathVariable int houseid,
                               @PathVariable int userid
    ){
        System.out.println("订单修改中..id:"+id+"  houseid"+houseid+"  userid:"+ userid);
        boolean flg = service.updateorder(id,houseid,userid);
        System.out.println("修改完毕，返回:"+flg);
        return flg;
    }





}
